home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / net-tools / aweb+tools / awebmail / awebmailsend.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1996-06-19  |  7.9 KB  |  227 lines

  1. /* Inline mail send arexx script for Aweb (w/ Voodoo Launch Option!)
  2.  
  3.     Version 1.2
  4.  
  5.     By Josef Faulkner (panther@gate.net) IRC: Josef
  6.  
  7.     Description:
  8.     ¯¯¯¯¯¯¯¯¯¯¯
  9.     This script is a mailto: plugin for Aweb.  This script will be run in
  10.     response to mailto: URLs, and will allow you to either compose a message
  11.     inside Aweb's GUI and send it, with NO need for any SMTP mailers, or you
  12.     can Launch Voodoo and let it handle the job.
  13.  
  14.     Features:
  15.     ¯¯¯¯¯¯¯¯¯
  16.         o Does not need an external SMTP mail program, does network stuff itself
  17.         if you have the TCP: network device installed.
  18.         o Can launch Voodoo instead, and this script will pass it the screenname
  19.           and address, and fill in a default subject.
  20.         o Runs transparently.  After you install, you don't even know it's there.
  21.         o Loads your signature into the <textarea> gadget.
  22.     New in 1.1:
  23.         o form action=mailto: submits now load form data into mail
  24.             Note: forms with over about 200 bytes of data will not work,
  25.             since AmigaDOS is limited to arguments at this size.
  26.             Also: Some forms do not submit the first time, I'm trying to find
  27.             out what conditions exist that causes some forms to submit and some
  28.             not, if you have any ideas on why this is so, please mail me.
  29.     New in 1.2:
  30.         o More RFC compliant.  Sorry I took so long to fix this.
  31.             o Passes hostname in HELO
  32.             o Passes email addresses inside of <>
  33.         o Allows you to use smtppost (though it may be slower).
  34.  
  35.     Installation:
  36.     ¯¯¯¯¯¯¯¯¯¯¯¯¯
  37.     1) Put this script in the same directory that the Aweb executable is in.
  38.     2) Set Aweb to the following settings:
  39.       ----------------------------------------------
  40.         Network 3: External Programs
  41.                    mailto:
  42.           Command:  sys:rexxc/rx
  43.         Arguments:  awebmailsend.rexx %s %s
  44.       ----------------------------------------------
  45.         Network 1: General
  46.         [ X ] Allow Shell commands in Links (check on)
  47.       ----------------------------------------------
  48.     3) Set your preferences for this script below:
  49. */
  50.  
  51. /* >--[ Settings - Customize for your system ]------------------------< */
  52. SMTPHost   = 'tequesta.gate.net'   /* Name of your SMTP host */
  53. VooDoo = 'N:Voodoo/Voodoo'         /* Voodoo's location on your drive */
  54. signature='DH2:net/.signature'         /* Location of your .signature */
  55. myemailaddress=''                  /* Set to your email address, or leave
  56.                                       blank, and it will look up your email
  57.                                       address from your ENV variables */
  58. /* Main Script */
  59. options results
  60. if ~show('L','rexxsupport.library') then if ~addlib('rexxsupport.library',0,-30,0) then exit(20)
  61. parse arg addr
  62.  
  63. if left(addr,1)='/' then addr=right(addr,length(addr)-1)
  64.  
  65. address command 'delete T:awebmail.#?.html >NIL:'
  66. fname='T:AwebMail.'time(S)'.html'
  67. if (~exists('env:username'))|(~exists('env:hostname')) then do
  68.     call open(4,fname,w)
  69.     call writeln(4,'<html><head><title>Error</title></head><body>')
  70.     call writeln(4,'<h1>Error</h1>')
  71.     call writeln(4,'<b>You have not configured your USERNAME and HOSTNAME env variables.</b><br>')
  72.     call writeln(4,'To do this, add the following lines to your User-Startup:<br>')
  73.     call writeln(4,'<pre>setenv USERNAME <myuserid>')
  74.     call writeln(4,'setenv HOSTNAME <myhostname')
  75.     call writeln(4,'</pre>')
  76.     call writeln(4,'For example, if your mail address is fred@kibo.org, you would set:')
  77.     call writeln(4,'<pre>setenv USERNAME fred')
  78.     call writeln(4,'setenv HOSTNAME kibo.org')
  79.     call writeln(4,'</pre><hr>')
  80.     call writeln(4,'<h2>Could not send mail.  Please set these variables and re-try</h2>')
  81.     call close(4)
  82.     address AWEB.1 'OPEN file://localhost/'fname
  83.     exit
  84. end
  85. if left(addr,9)~='postmail=' then do
  86.     if index(addr,'?')>0 then parse var addr addr'?'cmds' 'screen
  87.     else parse var addr addr' 'screen
  88.     if open(1,fname,w) then do
  89.         call writeln(1,'<html><head><title>')
  90.         call writeln(1,addr)
  91.         call writeln(1,'</title></head><body><h1>Mail to ')
  92.         call writeln(1,addr'</h1>')
  93.         call writeln(1,'<hr><form action="x-aweb:command/'voodoo' mail to 'addr' pubscreen 'screen'">')
  94.         call writeln(1,'<input type="submit" value="Use VooDoo!"></form>')
  95.         call writeln(1,'<form action="x-aweb:rexx/awebmailsend.rexx">')
  96.         call writeln(1,'<input type=hidden name=postmail value=true>')
  97.         call writeln(1,'or <input type=checkbox name=smtppost value="TRUE"> Click to Use SMTPpost instead of direct connection.')
  98.         call writeln(1,'<hr><tt>Mail to: <input size=60 name="touser" value="'addr'"><br>')
  99.         call writeln(1,'Subject: <input size=75 name="subj" value="mailto:'addr'"><br>')
  100.         call writeln(1,'Mail text:</tt><hr>')
  101.         if exists(signature) then do
  102.             call writeln(1,'<textarea name="otext" cols=75 rows=20>')
  103.             if index(cmds,'=')>0 then do
  104.                 call writeln(1,'Form data submitted from "mailto:" action:')
  105.                 do until cmds=''
  106.                     parse var cmds name'='value'&'cmds
  107.                     if left(cmds,1)='&' then cmds=right(cmds,length(cmds)-1)
  108.                     value=translate(value,' ','+')
  109.                     pos=index(value,'%')
  110.                     do until pos=0
  111.                         pos=index(value,'%')
  112.                         if pos>0 then do
  113.                             data=substr(value,pos,3)
  114.                             value=replace(value,data,x2c(right(data,2)))
  115.                         end
  116.                     end
  117.                     call writeln(1,'   'left(name,10,' ')'= 'value)
  118.                 end
  119.                 call writeln(1,'')
  120.             end
  121.             else do
  122.                 do n=1 to 4
  123.                     call writeln(1,'')
  124.                 end
  125.             end
  126.             call writeln(1,'--')
  127.             call open(2,signature,r)
  128.             do until eof(2)
  129.                 call writeln(1,readln(2))
  130.             end
  131.             call close(2)
  132.             call writeln(1,'</textarea>')
  133.         end
  134.         else do
  135.             call writeln(1,'<textarea name="data" cols=75 rows=20></textarea>')
  136.         end
  137.         call writeln(1,'<hr><input type="submit" value="Send Mail"></form>')
  138.         call writeln(1,'</body></html>')
  139.         call close(1)
  140.         address AWEB.1 'OPEN file://localhost/'fname
  141.     end
  142.     else address command 'RequestChoice "MailToRexx" "Error" "Ok" >NIL:'
  143. end
  144. else do
  145.     if open(1,fname,w) then do
  146.         call open(99,'t:test',w)
  147.         call writeln(99,addr)
  148.         call close(99)
  149.         do until addr=''
  150.             parse var addr name'="'value'"'addr
  151.             if left(addr,1)='&' then addr=right(addr,length(addr)-1)
  152.             interpret name'=value'
  153.         end
  154.         otext=left(otext,length(otext)-1)
  155.         otext=replace(otext,'*"','"')
  156.         otext=replace(otext,'*N',d2c(10))
  157.  
  158.         if myemailaddress='' then do
  159.             call open(7,'env:username',r)
  160.                 fromid=readln(7)
  161.             call close(7)
  162.             call open(7,'env:hostname',r)
  163.                 fromhost=readln(7)
  164.             call close(7)
  165.             from=fromid'@'fromhost
  166.         end
  167.         else from=myemailaddress
  168.  
  169.         data=replace(data,'.'d2c(13),'. 'd2c(13))
  170.         if exists('T:SentMail.txt') then call open(10,'T:SentMail.txt',a)
  171.         else call open(10,'T:SentMail.txt',w)
  172.         call writeln(10,'From: <'from'>')
  173.         call writeln(10,'To: 'touser)
  174.         call writeln(10,'Subject 'subj)
  175.         call writeln(10,'')
  176.         call writeln(10,otext)
  177.         call close(10)
  178.  
  179.         if(smtppost=TRUE) then do
  180.             address command 'run >NIL: smtppost <t:sentmail.txt'
  181.         end
  182.         else do
  183.             if ~showlist(H,'TCP') then address command 'mount TCP: from amitcp:devs/inet-mountlist'
  184.             if ~showlist(H,'TCP') then address command 'mount TCP:'
  185.             if showlist(H,'TCP') then do
  186.                 call open(8,'tcp:'smtphost'/25',w)
  187.                 call writeln(8,'HELO 'fromhost)
  188.                 call writeln(8,'MAIL FROM: <'from'>')
  189.                 call writeln(8,'RCPT TO: <'touser'>')
  190.                 call writeln(8,'DATA')
  191.                 call writeln(8,'From: <'from'>')
  192.                 call writeln(8,'To: 'touser)
  193.                 call writeln(8,'Subject: 'subj)
  194.                 call writeln(8,'')
  195.                 call writeln(8,otext)
  196.                 call writeln(8,'.')
  197.                 call writeln(8,'QUIT')
  198.                 call close(8)
  199.             end
  200.             else do
  201.                 address command 'Requestchoice title="SMTPSend" BODY="Mail NOT sent.  *nCouldn''t mount TCP:" GADGETS="Ok" >NIL:'
  202.                 exit
  203.             end
  204.         end
  205.  
  206.         otext=replace(otext,'<','<')
  207.         otext=replace(otext,'>','>')
  208.         call writeln(1,'<html><head><title>Mail to 'touser'</title></head><body>')
  209.         call writeln(1,'<h1>Mail sent to 'touser':</h1>')
  210.         call writeln(1,'<h2>'subj'</h2><pre>'otext)
  211.         call writeln(1,'</pre></body></html>')
  212.         call close(1)
  213.         address AWEB.1 'OPEN file://localhost/'fname
  214.     end
  215.     else address command 'Requestchoice title="SMTPSend" BODY="Mail Sent." GADGETS="Ok" >NIL:'
  216. end
  217. exit
  218.  
  219. REPLACE: procedure
  220. parse arg a,b,c
  221. d=index(a,b)
  222. do while d~=0
  223.     a=insert(c,delstr(a,d,length(b)),d-1)
  224.     d=index(a,b)
  225. end
  226. return a
  227.